package leetcode.erfen;

public class Test2 {
    public static void main(String[] args) {
        int[] nums = {1, 3, 5, 6, 7, 10, 15};
        System.out.println(searchInsert(nums, 8));
    }

    public static int searchInsert(int[] nums, int target) {
        int left = 0, right = nums.length - 1, ans = 0;
        while (left <= right) {
            int mid = (left + right) / 2;
            int tmp = nums[mid];
            if (target <= tmp) {
                ans = mid;
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return ans;
    }
}
